Conversation
doitchuu
approved these changes
Apr 14, 2026
| let zeroCount = 0; | ||
|
|
||
| while (s !== "1") { | ||
| const filtered = s.replace(/0/g, ""); |
Member
There was a problem hiding this comment.
replaceAll로 0을 모두 제거하기보다 정규 표현식을 활용하는 방법도 좋네요!
raejun92
approved these changes
Apr 15, 2026
| let zeroCount = 0; | ||
|
|
||
| while (s !== "1") { | ||
| const filtered = s.replace(/0/g, ""); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
이렇게 풀었어요
1. 최솟값 만들기
1) 복잡도 계산
시간 복잡도: O(n log n)
공간 복잡도: O(1)
2) 접근 아이디어
이 문제는 두 배열의 원소를 각각 한 번씩 사용해서 곱의 합이 최소가 되도록 만들어야 한다.
합을 최소로 만들려면 한쪽 배열의 가장 작은 값과 다른 쪽 배열의 가장 큰 값을 곱하는 방식으로 짝을 지어야 한다.
그래서 A 배열은 오름차순, B 배열은 내림차순으로 정렬한 뒤 같은 인덱스끼리 곱해서 모두 더했다.
2. 이진 변환 반복하기
1) 복잡도 계산
시간 복잡도: O(n)
공간 복잡도: O(n)
2) 접근 아이디어
이 문제는 문자열 s가 "1"이 될 때까지 이진 변환을 반복하면서,
총 몇 번 변환했는지와 제거한 0의 개수를 구하는 문제이다.
반복할 때마다 먼저 문자열에서 0을 모두 제거하고, 제거 전후 길이 차이를 이용해 삭제된 0의 개수를 누적한다.
그다음 남은 문자열의 길이를 2진수 문자열로 바꾸고 다시 같은 과정을 반복한다.
replace(/0/g, "")를 사용해 0을 한 번에 제거했고, 기존 길이 - 제거 후 길이로 없어진 0의 개수를 계산했다.